package com.nm.orm.dao.impl;

import com.nm.commons.exception.SupperException;
import com.nm.orm.dao.LabelDao;
import com.nm.orm.model.State;
import com.nm.orm.pojo.LabelEntity;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 功能说明：标签dao实现
 *
 * @return <br/>
 * 修改历史：<br/>
 * 1.[2017年02月12日上午17:30] 创建方法 by hw
 */
@Repository
@Qualifier("labelDao")
public class LabelDaoImpl extends DaoImpl<LabelEntity, String> implements LabelDao {

    public LabelDaoImpl() {
        super(LabelEntity.class);
    }

    private static final String STATE = "state";

    @Override
    public List<LabelEntity> findAll() throws SupperException {
        Criteria criteria = getCurrentSession(sessionFactory)
                .createCriteria(LabelEntity.class)
                .add(Restrictions.eq(STATE, State.ABLE.dbValue()));

        return criteria.list();
    }

}
